<?php
namespace Common\Model;

use Think\Model;

class AuthGroupModel extends Model
{
    public function getAuthGroup($id)
    {
        $group = $this->where(array("id" => $id))->find();
        $group["rules"] = "," . $group["rules"] . ",";
        return $group;
    }

    public function getAuthGroupList()
    {
        $list = $this->select();
        return $list;
    }

    public function addAuthGroup($data)
    {
        $group = array();
        if ($data["id"] == 0) {
            $group["title"] = $data["title"];
            $group["rules"] = implode(",", $data["rules"]);
            $this->add($group);
        } else {
            $group["title"] = $data["title"];
            $group["id"] = $data["id"];
            $group["rules"] = implode(",", $data["rules"]);
            $this->save($group);
        }

    }

    public function delAuthGroup($id)
    {
        $this->where(array("id" => $id))->delete();
    }

}